package com.frogs.ucenter.v1.request;

import javax.servlet.http.HttpServletRequest;

import com.frogs.framework.util.StringUtil;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.exception.RequestIllegalException;

/**
 * 用户是否登录验证请求参数类
 *
 * @author lijian
 * @version 2014年3月27日 - 下午1:56:54
 */
public class UserVerifyRequest extends Request {
	
	/**
	 * 用户ID
	 */
	private int userId;
	
	/**
	 * 用户当前所在的ip
	 */
	private String ip;
	
	/**
	 * 验证串
	 */
	private String verify;
	
	/** */
	public UserVerifyRequest() {
		
	}

	@Override
	public void parse(HttpServletRequest request) {
		
		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
		
		this.userId = requestInfo.getIntParameter(ApiUrlParamEnum.userId.getParamName(), 0);
		if (userId < 1) {
			throw new RequestIllegalException("error userId: " + userId);
		}
		
		this.verify = requestInfo.getParameter(ApiUrlParamEnum.verify.getParamName(), "");
		if (StringUtil.isEmpty(verify)) {
			throw new RequestIllegalException("error verify is null ");
		}
		
		this.ip = requestInfo.getParameter(ApiUrlParamEnum.ip.getParamName(), "");
		if ("127.0.0.1".equals(ip)) {
			this.ip = requestInfo.getUserIp();
		}
	}

	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	public String getVerify() {
		return verify;
	}

	public void setVerify(String verify) {
		this.verify = verify;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}
	
	

}
